using System;

namespace IPAddress
{
    internal class RangeReference : IComparable<RangeReference>
    {
        private readonly bool m_IsValue;

        // If the reference is to a line
        private readonly long m_Value;

        // If the reference is to a bar
        private readonly long m_Min;
        private readonly long m_Max;
       
        public RangeReference(long value)
        {
            m_IsValue = true;
            m_Value = value;
        }


        public RangeReference(long min, long max)
        {
            m_IsValue = false;
            m_Min = min;
            m_Max = max;
        }


        public int CompareTo(RangeReference other)
        {
            if (other.m_IsValue && m_IsValue)
            {
                if (m_Value > other.m_Value)
                {
                    return 1;
                }
                else if (m_Value < other.m_Value)
                {
                    return -1;
                }
                else
                {
                    return 0;
                }
            }

            if (!other.m_IsValue && !m_IsValue)
            {
                if (m_Min > other.m_Min
                    && m_Max > other.m_Max)
                {
                    return 1;
                }
                else if (m_Min < other.m_Min
                         && m_Max < other.m_Max)
                {
                    return -1;
                }
                else
                {
                    return 0;
                }
            }


            if (m_IsValue)
            {
                if (m_Value >= other.m_Max)
                {
                    return 1;
                }
                else if (m_Value <= other.m_Min)
                {
                    return -1;
                }
                else
                {
                    return 0;
                }
            }
            else
            {
                if (other.m_Value >= m_Max)
                {
                    return -1;
                }
                else if (other.m_Value <= m_Min)
                {
                    return 1;
                }
                else
                {
                    return 0;
                }
            }
        }
    }
}